package de.tum.in.eist.poll.service;

import java.util.List;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

import de.tum.in.eist.poll.shared.beans.Lecture;
import de.tum.in.eist.poll.shared.beans.Feedback;
import de.tum.in.eist.poll.shared.beans.Notification;
import de.tum.in.eist.poll.shared.beans.Question;
import de.tum.in.eist.poll.shared.beans.Student;
import de.tum.in.eist.poll.shared.beans.User;

@RemoteServiceRelativePath("pollService")
public interface PollService extends RemoteService {
	/**
	 * Requests a login by sending name and password.
	 * 
	 * @param name the name sent by the client
	 * @param password the password sent by the client
	 * @return the user corresponding to name and password
	 * @throws IllegalArgumentException if name and password don't match
	 */
	User login(String name, String password) throws IllegalArgumentException;
	
	/**
	 * Create new Students, add them to the store and return a list of them.
	 * The new students will be associated with the lecturer. In order to do
	 * that the lecturer has to be a known user with a known user ID. Otherwise
	 * a exception will be raised.
	 * 
	 * @param lecturerID The ID of the Lecturer of the students who are to be created
	 * @param prefix The common prefix of the students to create
	 * @param amount The amount of students to create
	 * @return list of the newly created students 
	 * @throws IllegalArgumentException Throws an exception if the amount is negative
	 * 		   or if the lecturer does not exist  
	 */
	List<Student> newStudents(String lecturerID, String prefix, Integer amount)
			throws IllegalArgumentException;
	
	/**
	 * TODO
	 * @param userIDs
	 * @return
	 */
	String removeUsers(String[] userIDs);
	
	/**
	 * Request the students for a lecturer.
	 * 
	 * @param lecturerID The ID of the lecturer for whose students should be returned
	 * @return the students belonging to the given lecturer
	 * @throws IllegalArgumentException
	 */
	List<Student> requestStudents(String lecturerID)
			throws IllegalArgumentException;
	
//	/**
//	 * Create a new lecturer with a custom userID and a custom password
//	 * 
//	 * @param userID
//	 * @param password
//	 * @return
//	 * @throws IllegalArgumentException
//	 */
//	Lecturer newLecturer(String userID, String password)
//			throws IllegalArgumentException;
	
	/**
	 * Adds a lecture to the store.
	 * 
	 * @param lecture the lecture to add
	 * @return some message
	 * @exception Throws an exception if the lecture contains invalid data
	 * 		(such as a nonexistent lecturer, null, ...)
	 */
	String addLecture(Lecture lecture)
			throws IllegalArgumentException;
	
	
	/**
	 * Requests a list of all lectures relevant to this user.
	 * The user passed must the same as the user in the data store
	 * in order to ensure consistency.
	 * 
	 * @param userID the ID of the user that requested this list
	 * @return a list of all lectures relevant to the user
	 */
	List<Lecture> requestLectures(String userID) throws IllegalArgumentException;
	
	/**
	 * Closes a poll on an lecture.
	 * 
	 * @param lectureID the lecture's ID
	 * @return some confirmation message
	 */
	String closePoll(String lectureID);
	
	/**
	 * Requests all feedback for a lecture.
	 * 
	 * @param lectureID the ID of the lecture the lecture to get feedback for
	 * @return all of the feedback corresponding to a lecture
	 */
	List<Feedback> requestFeedback(String lectureID);
	
	/**
	 * Submit feedback to the server.
	 * 
	 * @param feedback the feedback to submit.
	 * @return the server's answer
	 */
	String submitFeedback(Feedback feedback);
	
	/**
	 * TODO LONG
	 * @param lectureID
	 * @return
	 */
	Question[] getQuestions(String lectureID);
	
	/**
	 * Notify the users as specified by the user IDs
	 * 
	 * @param userIDs The IDs of the users to be notified
	 * @param notification The notification type
	 * @return true
	 */
	boolean sendNotification(String[] userIDs, Notification notification);
	
	/**
	 * Send a notification to students belonging to a lecturer
	 * 
	 * @param lecturerID   The lecturer's ID
	 * @param notification The notification type
	 * @return true
	 * @exception IllegalArguementError if lecturer specified by lecturerID does not exist
	 */
	boolean sendNotificationToStudents(String lecturerID, Notification notification)
			throws IllegalArgumentException;
	
	/**
	 * Returns true if there was a new Feedback submitted
	 * @param user the ID of the user who wants to be notified
	 * @return whether there was something new
	 */
	List<Notification> receiveNotification(String userID);
	
	/**
	 * 
	 * @param userID
	 * @param currentLectureId
	 * @param asyncCallback
	 */
	boolean hasSubmitted(String userId, String lectureId);
}
